
from bs4 import BeautifulSoup, NavigableString, Tag, Comment

def get_tag_content(soup):
    """
    获取标签内容
    """
    soup = BeautifulSoup(soup, 'html.parser') if not isinstance(soup, Tag) else soup
    for comment in soup.find_all(string=lambda text: isinstance(text, Comment)):
        comment.extract()
    # 提取纯文本
    pure_text = soup.get_text()
    # 清理多余的空白字符
    clean_text = ' '.join(pure_text.split())
    return clean_text